package policy.branches;

import policy.Policy;
import policy.nodes.Node;

/**
 * Returns the appropriate type of branch. Extend this class if you wish to use
 * more than the standard protocol,src_ip,src_port,dest_ip,dest_port
 * 
 * @author sscull
 * 
 */
public class BranchFactory {
	private final static String PROTOCOL = "protocol";
	private final static String IP = "ip";
	private final static String PORT = "port";
	private final static String ACTION = "action";

	public Branch getBranch(int field, String value, int rule) {
		if (Policy.FIELDS[field].contains(BranchFactory.PROTOCOL))
			return new ProtocolBranch(value, new Node(Policy.FIELDS[field + 1]));
		else if (Policy.FIELDS[field].contains(BranchFactory.IP))
			return new IPBranch(value, new Node(Policy.FIELDS[field + 1]));
		else if (Policy.FIELDS[field].contains(BranchFactory.PORT))
			return new PortBranch(value, new Node(Policy.FIELDS[field + 1]));
		else if (Policy.FIELDS[field].contains(BranchFactory.ACTION))
			return new ActionBranch(value, rule);
		else
			return null;
	}
}
